<?php
header('Content-Type:text/html;charset=utf-8');
if (!(empty($_POST)))  //不为空
{
    $username=isset($_POST["username"]) ? trim($_POST["username"])  : "";
    $password=isset($_POST["password"]) ? trim($_POST["password"])  : "";
    $re=isset($_POST["re"]) ? trim($_POST["re"])  : false;
    
    if (($username==="admin")   && ($password==="admin"))
    {
        //成功登录,并且你勾选了记住用户名，将这个用户名填到cookies里
        if ($re)
        {
            setcookie("cname",$username,time()+3600*24);
        }
        echo "ok";
    }
    else
     {
        echo "<script language='javascript' type='text/javascript'>";
        echo "alert('登录失败！');";
        echo "window.location.href='login.php'";
        echo "</script>"; 
    }
    
}
